package com.lkm.app_ui.m.Imple.fun;

import android.os.Handler;
import android.os.Looper;

import com.lkm.app_ui.AppConst;
import com.lkm.app_ui.RunTimeData;
import com.lkm.app_ui.log.SteelyardLogger;
import com.lkm.frame.task2.BackCallAdapter;
import com.lkm.frame.task2.Task;
import com.lkm.frame.task2.TaskAdapter;
import com.lkm.market2_0.m_imple.steelyardserver.SteelyardServerModuleBase;
import com.lkm.market2_0.m.steelyardserver.SteelyardServerModule;
import com.lkm.market2_0.m_imple.steelyardserver.server.AbsSendWriteTask;




public class LockKeySwitchTask extends TaskAdapter<Void, Void, Void> {

    Handler handler = null;

    @Override
    public void doExecuting(Void param) {
        super.doExecuting(param);
        handler = new Handler(Looper.getMainLooper());
        loop();
    }

    void loop() {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                SteelyardLogger.Hand.lockKeyStart();
                try {
                    SteelyardServerModule steelyardServerModule = AppConst.getModuleManager().loadModule(SteelyardServerModule.class);
                    AbsSendWriteTask absSendWriteTask = steelyardServerModule.setLockKeySwitch(RunTimeData.steelyardInfo.getSteelyardMac(), SteelyardServerModuleBase.isLock);
                    absSendWriteTask.addBackCall(new BackCallAdapter<Void,Boolean>(){
                        @Override
                        protected void onEnd(Task<?, Void, Boolean> task, Boolean aBoolean, boolean isCancel) {
                            super.onEnd(task, aBoolean, isCancel);
                            loop();
                        }
                    });
                } catch (Exception e) {
                    loop();
                }

            }
        }, 1000);

    }
}
